package com.somlsis.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.base.BaseAdapter
import com.clj.fastble.data.BleDevice
import com.somlsis.R

class SearchDeviceAdapter : BaseAdapter<BleDevice, SearchDeviceAdapter.ViewHolder> {

    constructor(
        context: Context,
        onItemClickListener: OnItemClickListener<BleDevice>
    ) : super(context) {
        this.onItemClickListener = onItemClickListener
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var name: TextView = itemView.findViewById(R.id.device_name)
        var mac: TextView = itemView.findViewById(R.id.device_mac)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflate: View =
            LayoutInflater.from(mContext).inflate(R.layout.item_search_device, parent, false)
        return ViewHolder(inflate)
    }

    override fun onBindView(holder: ViewHolder, position: Int, data: BleDevice?) {

        data?.let {
            holder.name?.let { v -> v.text = it.name }
            holder.mac?.let { v -> v.text = it.mac }
        }


    }
}